<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="用户名" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入用户名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="anchorList">
      <el-table-column label="主播名字" align="left" prop="anchorName" width="120" :show-overflow-tooltip="true"/>
      <el-table-column label="粉丝数量" align="left" prop="fansNumber" width="120" :show-overflow-tooltip="true"/>
      <el-table-column label="销量" align="center" prop="salesVolume" width="120" :show-overflow-tooltip="true"/>
      <el-table-column label="销售额" align="center" prop="salesQuota" width="140" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ $yun.priceFormatter(scope.row.salesQuota) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单数" align="center" prop="orderNumber" width="120" :show-overflow-tooltip="true"/>
      <el-table-column label="收益等级" align="center" prop="" width="120" :show-overflow-tooltip="true"/>
      <el-table-column label="联系方式" align="center" prop="phone" width="160" :show-overflow-tooltip="true"/>
      <el-table-column label="更新人" align="center" prop="updateBy" width="120" :show-overflow-tooltip="true"/>
      <el-table-column label="更新时间" align="center" prop="updateTime" width="200" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d} {h}:{h}:{s}') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="冻结身份" align="center" prop="anchorStatus" width="120">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.anchorStatus" active-color="#13ce66" inactive-color="#ff4949" :active-value="1"
                     :inactive-value="0" @change="disableChange(scope.row)"
          />
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="anchorStatus" width="120">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.audit_type" :value="scope.row.applyStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleDetails(scope.row)">查看主播信息</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!--    主播详情-->
    <el-dialog title="主播详情信息" :visible.sync="openDetails" width="800px" append-to-body>
      <el-descriptions class="margin-top" title="" :column="3" size="medium" border>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            姓名
          </template>
          {{ detailsObj.anchorName }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-mobile-phone"></i>
            联系方式
          </template>
          {{ detailsObj.phone }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-document"></i>
            主播状态
          </template>
          <dict-tag :options="dict.type.anchor_status" :value="detailsObj.anchorStatus"/>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-tickets"></i>
            审批状态
          </template>
          <dict-tag :options="dict.type.audit_type" :value="detailsObj.applyStatus"/>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-office-building"></i>
            粉丝数量
          </template>
          {{ detailsObj.fansNumber }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-goblet-full"></i>
            销量
          </template>
          {{ detailsObj.salesVolume }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-goblet-square"></i>
            销售额
          </template>
          {{ $yun.priceFormatter(detailsObj.salesQuota) }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            创建人
          </template>
          {{ detailsObj.createBy }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-c-scale-to-original"></i>
            创建时间
          </template>
          {{ detailsObj.createTime }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            更新人
          </template>
          {{ detailsObj.updateBy }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-pie-chart"></i>
            更新时间
          </template>
          {{ detailsObj.updateTime }}
        </el-descriptions-item>
      </el-descriptions>

    </el-dialog>

  </div>
</template>

<script>
import {
  listAnchor,
  getAnchor,
  anchorStatusChange,
} from '@/api/live/anchorList'

export default {
  name: 'Anchor',
  components: {},
  dicts: ['audit_type', 'anchor_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 主播表格数据
      anchorList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      open1: false,
      open2: false,
      open3: false,
      open4: false,
      open5: false,
      open6: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userId: [
          { required: true, message: '用户id不能为空', trigger: 'blur' }
        ],
        fansNumber: [
          { required: true, message: '粉丝数量不能为空', trigger: 'blur' }
        ],
        salesVolume: [
          { required: true, message: '销量不能为空', trigger: 'blur' }
        ],
        salesQuota: [
          { required: true, message: '销售额不能为空', trigger: 'blur' }
        ],
        order: [
          { required: true, message: '订单数不能为空', trigger: 'blur' }
        ],
        anchorStatus: [
          { required: true, message: '状态不能为空', trigger: 'change' }
        ],
        applyStatus: [
          { required: true, message: '申请审批状态不能为空', trigger: 'change' }
        ],
        delete: [
          { required: true, message: '是否删除不能为空', trigger: 'blur' }
        ],
        createTime: [
          { required: true, message: '创建时间不能为空', trigger: 'blur' }
        ],
        updateTime: [
          { required: true, message: '更新时间不能为空', trigger: 'blur' }
        ]
      },
      rules1: {
        shichang: [
          { required: true, message: '时长不能为空', trigger: 'blur' }
        ],
        dixin: [
          { required: true, message: '底薪不能为空', trigger: 'blur' }
        ]
      },
      detailsObj: {},
      openDetails: false,
      typeNew: null,
      newForm: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询主播列表 */
    getList() {
      this.loading = true
      listAnchor(this.queryParams).then(response => {
        this.anchorList = response.data.records
        this.total = response.data.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        anchorName: null,
        fansNumber: null,
        salesVolume: null,
        salesQuota: null,
        order: null,
        phone: null,
        anchorStatus: null,
        applyStatus: null,
        delete: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 修改按钮操作 */
    handleDetails(row) {
      const id = row.id || this.ids
      getAnchor(id).then(response => {
        this.detailsObj = response.data
        this.openDetails = true
      })
    },
    /** 身份冻结修改 */
    disableChange(row) {
      anchorStatusChange(row.id).then(response => {
        this.$modal.msgSuccess(response.msg)
        this.getList()
      })
    },
  }
}
</script>
<style lang="scss" scoped>
.detials-group {
  line-height: 40px;
  font-size: 16px;
  padding-left: 20px;
}
</style>
